<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style>
        #btn {
            text-indent: 3em;
        }
    </style>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td>姓名：</td>
        <td><input type="text" name="" id="1" value=""/></td>
    </tr>
    <tr>
        <td>留言：</td>
        <td><textarea rows="3" cols="40" id="2" style="margin: 0.625rem 0;"></textarea></td>
    </tr>
</table>
<div id="btn">
    <button type="button" onclick="res()">重置</button>
    <button type="button" onclick="fun()">留言</button>
</div>
<hr>
<textarea rows="20" cols="40" id="3" disabled="value">
		</textarea>
<script type="text/javascript">
    var arr = new Array();
    var a = document.getElementById("1");
    var b = document.getElementById("2");

    function res() {
        a.value = ""
        b.value = ""
    }

    function fun() {
        if (a.value == "" || b.value == "")
            alert("姓名或留言不能为空");
        else {
            var temp = "[" + a.value + "]在" + new Date().toLocaleTimeString() + "说：" + b.value;
            arr.unshift(temp);
            if (arr.length > 10)
                arr.pop();
            var k = arr.join("\n")
            document.getElementById("3").value = k;
        }
    }
</script>
</body>
</html>
